home *** CD-ROM | disk | FTP | other *** search
- unit ScopeTestMainForm;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TMainForm = class(TForm)
- Button1: TButton;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- public
- function Foo: Integer;
- procedure ShowInt(I: Integer);
- end;
-
- var
- MainForm: TMainForm;
-
- implementation
-
- uses
- ScopeTestOtherForm;
-
- {$R *.DFM}
-
- var
- Foo: Integer = 99;
-
- function TMainForm.Foo: Integer;
- begin
- Result := 1;
- end;
-
- procedure TMainForm.ShowInt(I: Integer);
- begin
- ShowMessageFmt('The value of this foo is: %d', [I])
- end;
-
- procedure TMainForm.Button1Click(Sender: TObject);
- const
- Foo: Integer = 57;
- begin
- //Access local variable, parameter or nested routine
- ShowInt(Foo); //57
- //Access data field or method of this class
- ShowInt(Self.Foo); //1
- //Access data field or method of other class
- ShowInt(OtherForm.Foo); //7
- //Access variable or routine from this unit
- ShowInt(ScopeTestMainForm.Foo); //99
- //Access variable or routine from other unit
- ShowInt(ScopeTestOtherForm.Foo); //100
- end;
-
- procedure TMainForm.Button2Click(Sender: TObject);
- const
- Foo: Integer = 57;
- begin
- with OtherForm do
- begin
- //Access local variable, parameter or nested routine
- //Cannot be done from inside this with statement
- //Access data field or method of this class
- ShowInt(Self.Foo); //1
- //Access data field or method of other class
- ShowInt(Foo); //7
- //Access variable or routine from this unit
- ShowInt(ScopeTestMainForm.Foo); //99
- //Access variable or routine from other unit
- ShowInt(ScopeTestOtherForm.Foo); //100
- end
- end;
-
- end.
-